home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / disk / misc / ADFlib.lha / Lib / Win32 / adf_nativ.c next >
C/C++ Source or Header  |  1999-02-08  |  2KB  |  119 lines

  1. /* Win32/adf_nativ.c - Win32 specific drive-access routines for ADFLib
  2.  *
  3.  * Modified for Win32 by Dan Sutherland <dan@chromerhino.demon.co.uk>
  4.  */
  5.  
  6. #include <windows.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. #include "../adf_str.h"
  11. #include "../adf_err.h"
  12.  
  13. #include "adf_nativ.h"
  14. #include "nt4_dev.h"
  15.  
  16. extern struct Env adfEnv;
  17.  
  18. RETCODE Win32InitDevice(struct Device* dev, char* lpstrName)
  19. {
  20.     struct nativeDevice* nDev;
  21.     char strTempName[3];
  22.  
  23.     nDev = (struct nativeDevice*)dev->nativeDev;
  24.  
  25.     nDev = (struct nativeDevice*)malloc(sizeof(struct nativeDevice));
  26.     if (!nDev) {
  27.         (*adfEnv.eFct)("Win32InitDevice : malloc");
  28.         return FALSE;
  29.     }
  30.  
  31.     /* convert device name to something usable by Win32 functions */
  32.     if (strlen(lpstrName) != 3) {
  33.         (*adfEnv.eFct)("Win32InitDevice : invalid drive specifier");
  34.         return FALSE;
  35.     }
  36.  
  37.     strTempName[0] = lpstrName[1];
  38.     strTempName[1] = lpstrName[2];
  39.     strTempName[2] = '\0';
  40.  
  41.     nDev->hDrv = NT4OpenDrive(strTempName);
  42.  
  43.     if (nDev->hDrv == NULL) {
  44.         (*adfEnv.eFct)("Win32InitDevice : NT4OpenDrive");
  45.         return FALSE;
  46.     }
  47.  
  48.     dev->size = NT4GetDriveSize(nDev->hDrv);
  49.  
  50.     dev->nativeDev = nDev;
  51.  
  52.     return RC_OK;
  53. }
  54.  
  55.  
  56. RETCODE Win32ReadSector(struct Device *dev, long n, int size, unsigned char* buf)
  57. {
  58.     struct nativeDevice* tDev;
  59.  
  60.     tDev = (struct nativeDevice*)dev->nativeDev;
  61.  
  62.     if (! NT4ReadSector(tDev->hDrv, n, size, buf)) {
  63.         (*adfEnv.eFct)("Win32InitDevice : NT4ReadSector");
  64.         return FALSE;
  65.     }
  66.  
  67.     return RC_OK;
  68. }
  69.  
  70.  
  71. RETCODE Win32WriteSector(struct Device *dev, long n, int size, unsigned char* buf)
  72. {
  73.     struct nativeDevice* tDev;
  74.  
  75.     tDev = (struct nativeDevice*)dev->nativeDev;
  76.  
  77.     if (! NT4WriteSector(tDev->hDrv, n, size, buf)) {
  78.         (*adfEnv.eFct)("Win32InitDevice : NT4WriteSector");
  79.         return FALSE;
  80.     }
  81.  
  82.     return RC_OK;
  83. }
  84.  
  85.  
  86. RETCODE Win32ReleaseDevice(struct Device *dev)
  87. {
  88.     struct nativeDevice* nDev;
  89.  
  90.     nDev = (struct nativeDevice*)dev->nativeDev;
  91.  
  92.     if (! NT4CloseDrive(nDev->hDrv))
  93.         return FALSE;
  94.  
  95.     free(nDev);
  96.  
  97.     return RC_OK;
  98. }
  99.  
  100.  
  101. void adfInitNativeFct()
  102. {
  103.     struct nativeFunctions *nFct;
  104.  
  105.     nFct = (struct nativeFunctions*)adfEnv.nativeFct;
  106.  
  107.     nFct->adfInitDevice = Win32InitDevice;
  108.     nFct->adfNativeReadSector = Win32ReadSector;
  109.     nFct->adfNativeWriteSector = Win32WriteSector;
  110.     nFct->adfReleaseDevice = Win32ReleaseDevice;
  111.     nFct->adfIsDevNative = Win32IsDevNative;
  112. }
  113.  
  114.  
  115. BOOL Win32IsDevNative(char *devName)
  116. {
  117.     return devName[0] == '|';
  118. }
  119.